 const app = getApp()
 import {
   convertToTree,
   deptAndGroupAndUserToConvert,
   deptAndTeamToConvert,
   deptToConvert,
   flattenTree,
   mapToArr
 } from "../../utils/util";
 import {
   createStoreBindings
 } from "mobx-miniprogram-bindings";
 import {
   deptSelectStore
 } from '../../store/deptSelectStore'

 // pagesFilter/filterDeptSelect/filterDeptSelect.js
 Page({

   /**
    * 页面的初始数据
    */
   data: {
     multiple: true,
     // 要返回的页面路径
     backToPath: '',
     dataList: [],
     sourceData: [],
     copyViewListData: [],
     viewListData: [],
     storeKey: '',
     echoValue: []
   },

   onConfirm({
     detail
   }) {
     this.confirm(detail.value, this.data.storeKey)
     wx.redirectTo({
       url: `${this.data.backToPath}`,
     })
   },
   onCancel() {
     wx.redirectTo({
       url: `${this.data.backToPath}`,
     })
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
     console.log('deptselect=====onLoad');
     this.storeBindings = createStoreBindings(this, {
       store: deptSelectStore,
       fields: ["choseDeptValue"],
       actions: ["confirm"],
     });
     this.storeBindings.updateStoreBindings()
     const is = {
       'false': false,
       'true': true
     }
     const {
       multiple,
       backToPath,
       choseType,
       storeKey
     } = options
     let sourceData = []
     let copyViewListData = []
     let viewListData = []
     // choseType: selectDept | selectDeptTeamUser | selectTeamUser
     // 部门选择
     if (choseType === 'selectDept') {
       sourceData = deptToConvert(app.globalData.deptList)
       const treeList = convertToTree(sourceData, {
         id: 'deptId',
         parentId: 'parentId',
         name: 'deptName'
       })
       copyViewListData = treeList
       viewListData = treeList
     } else if (choseType === 'selectDeptTeamUser') {
       // 部门小组人员选择
       const list = deptAndGroupAndUserToConvert(app.globalData.deptTeamUserList)
       copyViewListData = list
       viewListData = list
       sourceData = flattenTree(list)
     } else {
       // 小组人员选择
       const list = deptAndTeamToConvert(app.globalData.deptTeamUserList)
       copyViewListData = list
       viewListData = list
       sourceData = flattenTree(list)
     }
     this.setData({
       multiple: is[multiple],
       backToPath: backToPath,
       sourceData: sourceData,
       copyViewListData: copyViewListData,
       viewListData: viewListData,
       storeKey: storeKey,
       // echoValue: app_KeyValues(storeKey)
       echoValue: this.data.choseDeptValue.map(item => item.value)
     })



     // 

   },

   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady() {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow() {

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide() {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload() {
     this.storeBindings.destroyStoreBindings();
   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh() {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom() {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage() {

   }
 })